<template>
    <div class="col card p10">
        <label class="title">流量计参数</label>
        <div class="row_center mt">
            <label class="less">每升脉冲数量:</label>
            <el-input class="num_input" size="small" v-model="ctx.count"/>
            <label class="less">个</label>
        </div>
        <div class="row_center mt">
            <el-button @click="onClickQuery" type="warning">查询</el-button>
            <el-button @click="onClickSet" type="primary">设置</el-button>
        </div>
    </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue';
import { dialog } from '../../service/ui';
import { set_flow_info, get_flow_info } from '../../service/heat_cmd';
import { delay } from '../../service/utils';

interface Ctx {
    count: string,
}

const ctx = reactive<Ctx>({
    count: '1000',
});

async function onClickQuery() {
    try {
        const info = await get_flow_info();
        ctx.count = '';
        await delay(50);
        ctx.count = `${info}`;
    } catch (msg) {
        dialog.err(msg);
    }
}

async function onClickSet() {
    if (ctx.count.length == 0) {
        dialog.err('请输入参数');
        return;
    }

    try {
        const count = parseInt(ctx.count);
        await set_flow_info(count);
        dialog.succ('设置成功');
    } catch (msg) {
        dialog.err(msg);
    }
}

</script>

